package de.rosstauscher.jculfw.fs20;

import de.rosstauscher.jculfw.IRawMessageProcessor;

/**********************************************************
 * This a base class for listeners that want to process FS20 messages.
 * You just have to implement the processFS20Message method in your 
 * own implementation.
 * 
 * @author Rossi java@rosstauscher.de
 *********************************************************/

public abstract class FS20MessageProcessor implements IRawMessageProcessor {

	/* (non-Javadoc)
	 * @see de.rosstauscher.jculfw.RawMessageListener#parseInput(java.lang.String)
	 */
	public boolean parseInput(String data) {
		if (data.startsWith("F") && data.length() >= 8) {
			String houseCode = data.substring(1, 5);
			String deviceID = data.substring(5,7);
			FS20CommandCode command = FS20CommandCode.fromHex(data.substring(7,9));
			processFS20Message(houseCode, deviceID, command);
			return true;
		}
		return false;
	}
	
	/**********************************************************
	 * Implement this method to process the FS20 message.
	 * @param houseCode of the target
	 * @param deviceID of the target
	 * @param command to execute by the target.
	 *********************************************************/
	
	protected abstract void processFS20Message(String houseCode, String deviceID, FS20CommandCode command);

}
